#encoding=utf-8
import socket
import time
import numpy
 
host = "192.168.137.84"      #服务器ip
#查询本机IP命令
# $ hostname -I
#Formation 下
#一号机：192.168.137.84
#二号机:192.168.137.59
#HITSZ 下
#一号机：10.250.107.202
#二号机：10.250.207.224
#host = "127.0.0.1"      #服务器ip
port = 6668               #服务器端口号
A = [2.13,',',2.14,',',1]
B = [2.13,',',2.14,',',2]
C = [2.13,',',2.14,',',3]
mssg=[]
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    # 选择IPv4地址以及TCP协议
print ("通信服务开启")
mySocket.bind((host, port))   # 绑定端口
mySocket.listen(5)       # 监听这个端口，可连接最多5个设备
str1 = ''.join(str(i) for i in A)
mssg1 = str1.encode()
str2 = ''.join(str(i) for i in B)
mssg2 = str2.encode()
str3 = ''.join(str(i) for i in C)
mssg3 = str3.encode()
if __name__ == '__main__':
    client, address = mySocket.accept()           # 接受客户端的连接请求
    try:
        client.settimeout(120)                 # 设置2min时限
        client.send(mssg1)
        print("发送成功1")
        time.sleep(5)
    except socket.timeout:                # 超时
        print ('time out')
    try:
        client.settimeout(120)                 # 设置2min时限
        client.send(mssg2)
        print("发送成功2")
        time.sleep(5)
    except socket.timeout:                # 超时
        print ('time out')
    try:
        client.settimeout(120)                 # 设置2min时限
        client.send(mssg3)
        print("发送成功3")
        time.sleep(5)
    except socket.timeout:                # 超时
        print ('time out')
    mySocket.close()          # 关机
